package com.umpay.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 加载配置
 * 
 * @ClassName ProFileUtil
 * @Description TODO
 * @author FENG JUN LIU
 * @Date 2018年1月29日
 * @version 1.0.0
 */
public class ProFileUtil {

    private static final String fileName = "SignVerProp.properties";
    private static final Logger log = LoggerFactory.getLogger(ProFileUtil.class);
    public static byte[] getFileByte(String pro) throws IOException {
        byte[] b = null;
        InputStream in = null;
        try {
            Properties prop = new Properties();
            in = ProFileUtil.class.getClassLoader().getResourceAsStream(fileName);
            if (in == null) {
                throw new RuntimeException("没有找到配置文件:" + fileName);
            }
            prop.load(in);
            in.close();
            String filepath = prop.getProperty(pro);
            log.info(String.format("平台证书名称[%s]",filepath));
            if (filepath == null) {
                throw new RuntimeException("没有找到配置信息" + pro);
            }
            try {
                in = new FileInputStream(new File(filepath));
            } catch (Exception e) {
                in = ProFileUtil.class.getClassLoader().getResourceAsStream(filepath);
            }
            if (in == null) {
                throw new RuntimeException("文件不存在" + filepath);
            }
            b = new byte[20480];
            in.read(b);
        } finally {
            if (in != null) {
                in.close();
            }
        }
        return b;
    }

}
